$(function() {

	let loadData = function() {
		$.get("news-img.do", function(data) {
			formatData(data);
		}, "json");
	};
	let firstOl = $("ol");
	let img = $(".item");
	let imgParent = img.parent();

	let firstLi = firstOl.children().remove();
	let imgDiv = imgParent.children().remove();
	let formatData = function(list) {
		firstOl.empty();
		imgParent.empty();
		$.each(list, function(i, item) {
			var newsContent = item.newsContent;
			var index = newsContent.lastIndexOf("src")
			var s = newsContent.substr(index + 5);
			s = s.substr(0, s.indexOf("\""));
			console.info(s);
			let l = firstLi.clone().appendTo(firstOl);
			let img = imgDiv.clone().appendTo(imgParent);

			if (i == 0) {
				l.attr("class", "active");
				img.attr("class", "item active");
			}
			l.attr("data-slide-to", i);
			if (index == -1) {
				img.find("img").attr("src", "img/_noimg.png");
			} else if (s != null && s != "" && s != undefined) {
				img.find("img").attr("src", s);
			
			} else {
				img.find("img").attr("src", "img/_noimg.png");
			}
			img.find("h4").text(item.newsTitle);
			img.find("a").attr("href", "news-show-" + item.newsId + ".html");
		});
	}
	loadData();

});